import QtQuick 2.6
import QtQuick.Layouts 1.1
import QtGraphicalEffects 1.0
import QtQml.Models 2.2

import org.kde.plasma.core 2.0 as PlasmaCore
Column {
    id: root
    signal sendWinId()
    signal sendMoveEntered()
    signal sendMoveLeaved()
    signal sendRightButtonClicked()

    Rectangle {
        id: rect1
        objectName: "rect1";
        width: temp_width*1
        height: temp_height*1
        property int temp_width:100
        property int temp_height:100
        anchors.horizontalCenter: parent.horizontalCenter
        visible: true
        //        activeFocus: true	//留着这行会段错误
        activeFocusOnTab: true
        focus: true
        enabled: true
        color:"#00000000"

        function setValue(value_width, value_height)
        {
            temp_width = value_width;
            temp_height = value_height;

        }

        Component.onCompleted: {
            console.debug("main.qml log");
            console.debug("temp_width=",temp_width);
            console.debug("temp_height=",temp_height);
        }

        // 缩略图
        PlasmaCore.WindowThumbnail {
            id: tmpWindowThumbnail
            objectName: "tmpWindowThumbnail"
            anchors.fill: parent
            visible: true
            enabled: true
        }

        MouseArea {
            anchors.fill: parent
            acceptedButtons: Qt.LeftButton | Qt.RightButton
            onClicked: {
                // TODO:
                if (mouse.button == Qt.LeftButton) {
                    console.log("left mouse button");
                    root.sendWinId()
                }
                if (mouse.button == Qt.RightButton) {
                    console.log("right mouse button");
                    root.sendRightButtonClicked()
                }
            }

            onExited: {
                console.log("leave qml..");
                root.sendMoveLeaved()
            }

            //ljlj 只在光标进入后执行一次
            hoverEnabled: true
            onEntered: {
                console.log("enter qml..");
                console.debug("temp_width=",rect1.width);
                console.debug("temp_height=",rect1.height);
                console.debug("tmpWindowThumbnail=",tmpWindowThumbnail.width);
                console.debug("tmpWindowThumbnail=",tmpWindowThumbnail.height);
                root.sendMoveEntered()
            }

            //ljlj 在光标进入和出去后，都会执行一次，执行两次
//            hoverEnabled: true
//            onContainsMouseChanged: {
//                //                console.debug("ljlj onContainsMouseChanged");
//                console.log("ljlj enter qml..");
//                root.sendMoveEntered()
//            }
        }
    }
}

